home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / VIEWEX.PAK / SPLITTER.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  5KB  |  185 lines

  1. // splitter.cpp : implementation file
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1995 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "viewex.h"
  15. #include "splitter.h"
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char BASED_CODE THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CSplitterFrame
  24.  
  25. // Create a splitter window which splits an output text view and an input view
  26. //                           |
  27. //    TEXT VIEW (CTextView)  | INPUT VIEW (CInputView)
  28. //                           |
  29.  
  30. IMPLEMENT_DYNCREATE(CSplitterFrame, CMDIChildWnd)
  31.  
  32. CSplitterFrame::CSplitterFrame()
  33. {
  34. }
  35.  
  36. CSplitterFrame::~CSplitterFrame()
  37. {
  38. }
  39.  
  40.  
  41. BOOL CSplitterFrame::OnCreateClient(LPCREATESTRUCT,
  42.      CCreateContext* pContext)
  43. {
  44.     // create a splitter with 1 row, 2 columns
  45.     if (!m_wndSplitter.CreateStatic(this, 1, 2))
  46.     {
  47.         TRACE0("Failed to CreateStaticSplitter\n");
  48.         return FALSE;
  49.     }
  50.  
  51.     // add the first splitter pane - the default view in column 0
  52.     if (!m_wndSplitter.CreateView(0, 0,
  53.         pContext->m_pNewViewClass, CSize(130, 50), pContext))
  54.     {
  55.         TRACE0("Failed to create first pane\n");
  56.         return FALSE;
  57.     }
  58.  
  59.     // add the second splitter pane - an input view in column 1
  60.     if (!m_wndSplitter.CreateView(0, 1,
  61.         RUNTIME_CLASS(CInputView), CSize(0, 0), pContext))
  62.     {
  63.         TRACE0("Failed to create second pane\n");
  64.         return FALSE;
  65.     }
  66.  
  67.     // activate the input view
  68.     SetActiveView((CView*)m_wndSplitter.GetPane(0,1));
  69.  
  70.     return TRUE;
  71. }
  72.  
  73. BEGIN_MESSAGE_MAP(CSplitterFrame, CMDIChildWnd)
  74.     //{{AFX_MSG_MAP(CSplitterFrame)
  75.     //}}AFX_MSG_MAP
  76. END_MESSAGE_MAP()
  77.  
  78. /////////////////////////////////////////////////////////////////////////////
  79. // C3WaySplitterFrame - just like CSplitterFrame except the input view is
  80. //   the first pane, and there are two output views
  81.  
  82. //                             |  Text View (CTextView)
  83. //    INPUT VIEW (CInputView)  |------------------------
  84. //                             |  Color View (CColorView)
  85.  
  86. IMPLEMENT_DYNCREATE(C3WaySplitterFrame, CMDIChildWnd)
  87.  
  88. C3WaySplitterFrame::C3WaySplitterFrame()
  89. {
  90. }
  91.  
  92. C3WaySplitterFrame::~C3WaySplitterFrame()
  93. {
  94. }
  95.  
  96.  
  97. BOOL C3WaySplitterFrame::OnCreateClient(LPCREATESTRUCT lpcs,
  98.      CCreateContext* pContext)
  99. {
  100.     // create a splitter with 1 row, 2 columns
  101.     if (!m_wndSplitter.CreateStatic(this, 1, 2))
  102.     {
  103.         TRACE0("Failed to CreateStaticSplitter\n");
  104.         return FALSE;
  105.     }
  106.  
  107.     // add the first splitter pane - the default view in column 0
  108.     if (!m_wndSplitter.CreateView(0, 0,
  109.         pContext->m_pNewViewClass, CSize(200, 50), pContext))
  110.     {
  111.         TRACE0("Failed to create first pane\n");
  112.         return FALSE;
  113.     }
  114.  
  115.     // add the second splitter pane - which is a nested splitter with 2 rows
  116.     if (!m_wndSplitter2.CreateStatic(
  117.         &m_wndSplitter,     // our parent window is the first splitter
  118.         2, 1,               // the new splitter is 2 rows, 1 column
  119.         WS_CHILD | WS_VISIBLE | WS_BORDER,  // style, WS_BORDER is needed
  120.         m_wndSplitter.IdFromRowCol(0, 1)
  121.             // new splitter is in the first row, 2nd column of first splitter
  122.        ))
  123.     {
  124.         TRACE0("Failed to create nested splitter\n");
  125.         return FALSE;
  126.     }
  127.  
  128.     // now create the two views inside the nested splitter
  129.     int cyText = max(lpcs->cy - 70, 20);    // height of text pane
  130.  
  131.     if (!m_wndSplitter2.CreateView(0, 0,
  132.         RUNTIME_CLASS(CTextView), CSize(0, cyText), pContext))
  133.     {
  134.         TRACE0("Failed to create second pane\n");
  135.         return FALSE;
  136.     }
  137.     if (!m_wndSplitter2.CreateView(1, 0,
  138.         RUNTIME_CLASS(CColorView), CSize(0, 0), pContext))
  139.     {
  140.         TRACE0("Failed to create third pane\n");
  141.         return FALSE;
  142.     }
  143.  
  144.     // it all worked, we now have two splitter windows which contain
  145.     //  three different views
  146.     return TRUE;
  147. }
  148.  
  149. BEGIN_MESSAGE_MAP(C3WaySplitterFrame, CMDIChildWnd)
  150.     //{{AFX_MSG_MAP(C3WaySplitterFrame)
  151.     //}}AFX_MSG_MAP
  152. END_MESSAGE_MAP()
  153.  
  154. /////////////////////////////////////////////////////////////////////////////
  155. // 
  156.  
  157. IMPLEMENT_DYNAMIC(CViewExSplitWnd, CSplitterWnd)
  158.  
  159. CViewExSplitWnd::CViewExSplitWnd()
  160. {
  161. }
  162.  
  163. CViewExSplitWnd::~CViewExSplitWnd()
  164. {
  165. }
  166.  
  167. CWnd* CViewExSplitWnd::GetActivePane(int* pRow, int* pCol)
  168. {
  169.     ASSERT_VALID(this);
  170.  
  171.     // attempt to use active view of frame window
  172.     CWnd* pView = NULL;
  173.      CFrameWnd* pFrameWnd = GetParentFrame();
  174.     ASSERT_VALID(pFrameWnd);
  175.     pView = pFrameWnd->GetActiveView();
  176.  
  177.     // failing that, use the current focus
  178.     if (pView == NULL)
  179.         pView = GetFocus();
  180.  
  181.     return pView;
  182. }
  183.  
  184.  
  185.